package com.tomorrow.runner.service;

import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

public class Result implements Parcelable {
	private static final String KEY_ERROR = "error";
	private static final String KEY_RESULT = "result";
	// private static final String KEY_RESULT_TYPE = "result_type";

	private Bundle mBundle;

	public Result() {
		mBundle = new Bundle();
	}

	public void setError(Throwable t) {
		mBundle.putSerializable(KEY_ERROR, t);
	}

	public void setResult(Parcelable data) {
		mBundle.putParcelable(KEY_RESULT, data);
	}

	public Throwable getError() {
		return (Throwable) mBundle.getSerializable(KEY_ERROR);
	}

	public <T extends Parcelable> T getResult() {
		return mBundle.getParcelable(KEY_RESULT);
	}

	public Bundle getBundle() {
		return mBundle;
	}

	public static final Parcelable.Creator<Result> CREATOR = new Parcelable.Creator<Result>() {
		public Result createFromParcel(Parcel in) {
			return new Result(in);
		}

		public Result[] newArray(int size) {
			return new Result[size];
		}
	};

	private Result(Parcel in) {
		readFromParcel(in);
	}

	private void readFromParcel(Parcel in) {
		mBundle = in.readBundle();
		mBundle.setClassLoader(getClass().getClassLoader());
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeBundle(mBundle);
	}

}
